package com.eatme.core.design.pattern.creational.simplefactory;

/**
 * 简单工厂
 * 类型: 创建型
 * 定义:
 * 优点:
 * 缺点:
 * 试用场景:
 */
public class VideoFactory {
    public Video getVideo(Class c) {
        Video video = null;
        try {
            video = (Video) Class.forName(c.getName()).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return video;
    }


    public Video getVideo(String type) {
        if ("java".equalsIgnoreCase(type)) {
            return new JavaVideo();
        }else if ("python".equals(type)) {
            return new PythonVideo();
        }
        return null;
    }
}
